package org.example.entity;

import com.almasb.fxgl.entity.Entity;
import javafx.scene.shape.Line;
import org.example.inter.Grasped;

import java.util.Optional;


public class HookEntity {

    /**
     * 方向
     */
    private int dir = 1;


    /**
     * 初始速度
     */
    private double speed = 0.4;

    /**
     * 速度等级
     */
    private double speedLevel = 0;

    /**
     * 每级增加速度
     */
    private double increment = 0.3;

    /**
     * 钩子伸出速度
     */
    private double grabSpeed = 3;

    private double recycleSpeed = 3d;

    /**
     * 抓取的物品
     */
    private Grasped obj;


    public int getDir() {
        return dir;
    }

    public void setDir(int dir) {
        this.dir = dir;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public double getSpeedLevel() {
        return speedLevel;
    }

    public void setSpeedLevel(double speedLevel) {
        this.speedLevel = speedLevel;
    }

    public double getIncrement() {
        return increment;
    }

    public void setIncrement(double increment) {
        this.increment = increment;
    }

    public double getSwingSpeed() {
        return ((speed + (speedLevel * increment)) * dir);
    }

    public double getGrabSpeed() {
        return grabSpeed;
    }

    public double getRecycleSpeed() {
        double v =  ((Optional.ofNullable(obj).map(Grasped::getWeight).orElse(0d)) * 0.2);
        if(v>= recycleSpeed) {
            return 0.5;
        }
        return recycleSpeed - v;
    }

    public Grasped getObj() {
        return obj;
    }

    public void setObj(Grasped obj) {
        this.obj = obj;
    }
}
